# Deployment #
This section documents common approaches to deploying the service gateway.

## Deploying from the Management Console ##

The Service Gateway Management Console is a separate web site which provides a task oriented user interface for configuring a Gateway as well as managing the deployment of the Gateway and display of application analytics.

The Service Gateway Management Console website can be found in the *Microsoft Azure Websites Gallery*, under the *App Frameworks* section. Create a new website by selecting this gallery option, specifying the database and *Microsoft Azure Active Directory (AAD)* information and click *Create*.

More details about prerequisites and user help can be found in the [Management Console User Guide](Console).

## Hosting the Gateway Configuration Files ##

As described in the [Role Configuration Guide](Roles) the required *Role Index* and *Role* configuration files must be accessible via a public HTTP(S) URL. In the case where the Gateway is not being deployed from the Management Console (as described above), the configuration must be hosted externally.

The Gateway will request the configuration files at service startup and then approximately once every minute to detect changes to the configuration. The service hosting the configuration must reply with a JSON document (content type: 'application/json') that conforms to the format as described in the reference. The configuration hoster may choose to serve static configuration files (this is the easiest solution and *Microsoft Azure Storage Blobs* provide an excellent mechanism, but dynamic flexibility is naturally limited). Alternatively, configurations may be served by a service backed by a database - this solution works well for non-trivial and/or dynamic configuration environments.

## Deploying from the Microsoft Azure Portal ##

The Service Gateway can be deployed to an *Microsoft Azure Hosted Service* by using the pre-built package and service configuration files. The files are available at the following locations:

**No HTTPS endpoint**

- Service Package: [https://www.service-gateway.net/gateway/latest/http/CloudProject.cspkg](https://www.service-gateway.net/gateway/latest/http/CloudProject.cspkg) 
- Service Configuration: [https://www.service-gateway.net/gateway/latest/http/ServiceConfiguration.Publish.cscfg](https://www.service-gateway.net/gateway/latest/http/ServiceConfiguration.Publish.cscfg)

**Includes HTTPS endpoint (TLS certificate must be uploaded separately)**

- Service Package: [https://www.service-gateway.net/gateway/latest/https/CloudProjectHttps.cspkg](https://www.service-gateway.net/gateway/latest/https/CloudProjectHttps.cspkg) 
- Service Configuration: [https://www.service-gateway.net/gateway/latest/https/ServiceConfiguration.Publish.cscfg](https://www.service-gateway.net/gateway/latest/https/ServiceConfiguration.Publish.cscfg)

Copy the configuration file to your local computer. Using a text editor, modify the configuration values to point to the location of the *Role Index* configuration file (see previous section for hosting configuration files) as well as the storage account details for storing the web logs and other diagnostic information.

The *Microsoft Azure Management Portal* does not permit creating a service using a package stored in a storage account that is not part of the current subscription and so you will need to download the service package file to your local computer. If you have an Azure management tool that permits deploying a service using a package from anywhere, you will not need to download the service package file.

Once the service has been deployed, it will apply the configuration and begin routing requests.   

## From Visual Studio ##

*Visual Studio* provides the ability to deploy a hosted service directly from code. You will first need to download the entire code tree and open the *Gateway.sln* solution in *Visual Studio*. In the *CloudProject* project, make changes to the *ServiceConfiguration.Publish.cscfg* file as described in the previous section.

Right-click on the *CloudProject* project in the *Solution Explorer* and select `Publish...`. Enter the details of your subscription and target service and click *Publish*. *Visual Studio* will display progress as the package is compiled and then uploaded to *Microsoft Azure*. Once the status as shown as *Completed* the Gateway will be configured and ready to route requests.

**Note:** When the Gateway solution is open in *Visual Studio*, avoid running the *CloudProject* project in the local emulator. While the reverse proxy itself will operate correctly in the emulator, all of the startup scripts will adversely affect the rest of your development computer.

### Support for Test SSL Certificates ###

When incorporating deployment of the Service Gateway into your own development workflow, you are able to add support for proxying requests for roles over HTTPS that do not feature a valid SSL certificate. See [Test SSL Certificates](TestSslCertSupport) for full details on including support for this scenario.


